package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @Author Justin Parker
 * @Date 2024/7/30 0030 15:24
 * @Version 1.0
 */
/*
    DBUtil工具类测试;
 */
public class JDBCDemo04 {
    public static void main(String[] args) {

        try {
            //创建数据库连接对象【利用工具类】
            Connection connection = DBUtil.getConnection();
            Statement statement = connection.createStatement();
            //用户输入
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户名");
            String username = scanner.nextLine();
            //sql语句
            String sql = "delete from userinfo where username='"+username+"'";
            int i = statement.executeUpdate(sql);
            if (i>0){
                System.out.println("注销成功");
            }else {
                System.out.println("注销失败");
            }

            statement.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

}
